package com.ipad.ui;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;

import com.ipad.R;
import com.ipad.utils.ActivityStack;
import com.ipad.utils.StatusBarUtils;
import com.ipad.view.dialog.LoadingDialog;

import butterknife.ButterKnife;
import pub.devrel.easypermissions.EasyPermissions;

/**
 * Created by Administrator on 2018/12/3.
 */

public abstract class BaseActivity extends AppCompatActivity {
    public LoadingDialog loadingDialog;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getLayoutId());
        ButterKnife.bind(this);
        ActivityStack.getInstance().addActivity(this);

        initView();
        initData();

        setToolbar();
        loadingDialog = new LoadingDialog(this, R.style.loading_style);
        StatusBarUtils.setColor(this, getResources().getColor(R.color.black));
    }

    public abstract int getLayoutId();

    public abstract void initView();

    public abstract void initData();

    public abstract void setToolbar();


    public void showDialog(String msg) {
        if (loadingDialog != null && !loadingDialog.isShowing()) {
            loadingDialog.showDialog(msg);
        }
    }

    public void dismissDialog() {
        if (loadingDialog != null && loadingDialog.isShowing()) {
            loadingDialog.dismiss();
            loadingDialog.cancel();
        }
    }

    public boolean hasPresmisson(String[] prems) {
        boolean b = EasyPermissions.hasPermissions(getApplicationContext(), prems);
        return b;
    }

    @Override
    protected void onDestroy() {
        ActivityStack.getInstance().removeActivity(this);
        super.onDestroy();
    }
}
